<?php

class Gold_Aweber_Model_Observer extends Varien_Object {

    /**
     * 
     * @param Varien_Event_Observer $o
     */
    public function afterSaveSubscription($o) {
        $newSubscriberInst = $o->getEvent ()->getDataObject ();
        if ($newSubscriberInst->isSubscribed ()) {
            $http = new Varien_Http_Adapter_Curl();
        	$ip=$_SERVER['REMOTE_ADDR'];
			$headers['CLIENT-IP'] = $ip;  
			$headers['X-FORWARDED-FOR'] = $ip; 
			$headerArr = array();
			  
			foreach( $headers as $n => $v ) {  
			    $headerArr[] = $n .':' . $v;   
			}
            $config = array('timeout' => 30);
            $http->setConfig($config);
            $Query = array(
                'meta_web_form_id'=>'2031196674',
                'meta_split_id'=>'',
                'listname'=>'gold-customers',
                'redirect'=>'http://www.sw-box.com/newsletter-submit.html',
                'meta_redirect_onlist'=>'http://www.sw-box.com/oops-already-subscribed-try-different-email-address-.html',
                'meta_adtracking'=>'sw-box.com',
                'meta_message'=>'1',
                'meta_required'=>'email',
                'meta_tooltip'=>'',
                'email'=>$newSubscriberInst->getEmail()
            );
            $Url = 'http://www.aweber.com/scripts/addlead.pl';
            $http->write(Zend_Http_Client::POST,$Url,'1.1',$headerArr,http_build_query($Query));
            $response = $http->read();
            $http->close();
        }
        return $this;
    }
}	
